package se.penselnsvag.bookdb.module.book
{
	import mx.collections.ArrayCollection;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.remoting.RemoteObject;
	
	import se.penselnsvag.bookdb.tech.rpc.DataListener;
	
	public class BookService
	{
		private static var instance:BookService;
		
		private var ro:RemoteObject;
		
		public static function getInstance():BookService {
			if(instance==null)
				instance= new BookService(new SingletonBlocker());
				
			return instance;
		}
		
		public function BookService(sb:SingletonBlocker)
		{
			if(sb==null)
				throw new Error("BookService is a singleton user BookService.getInstance() instead!");
			init();
		}
		
		private function init():void {
			ro = new RemoteObject("amfphp");
			ro.source="bookdb.BookService";
		}
		
		public function getAllBooks(dl:DataListener):void {
			ro.addEventListener(ResultEvent.RESULT, dl.dataUpdate);
			ro.addEventListener(FaultEvent.FAULT, dl.dataFault);
			ro.getAllBooks();
		}

	}
}

class SingletonBlocker {}